<?php
require 'auth.php';
require '../config/config.php';

if(!isset($_GET['id'])){
	header("Location: ../authors.php");
	exit();
}
mydb_connect();
$qry = $conn->prepare("SELECT * FROM `news` WHERE id = :id");
$qry->execute(array('id' => $_GET['id']));
while($row = $qry->fetch()){
	if(file_exists("../../author/images/" . $row['img_name'])){
	$unlink = unlink("../../author/images/" . $row['img_name']);
	if(!$unlink){
		echo "ERROR";
		exit();
	}
	}
}
$qry = $conn->prepare("DELETE FROM `users` WHERE id = :id");
$qry->execute(array('id' => $_GET['id']));

	if($qry){
		header("Location: ../authors.php?delete=success");
	}
	else{
		echo $delete->errorInfo();
	}
?>